package com.pan.template.ctrl;

import com.pan.utils.UmlConfig;

public enum CtrlClassXY {

    INSTANCE;

    private int startX;
    private int startY;

    private int currentX;
    private int currentY;

    private int maxClassHeight;

    private int xBetween;
    private int yBetween;

    private int pictureWidthLimit;
    {
        startX = UmlConfig.INSTANCE.getX();
        startY = UmlConfig.INSTANCE.getY();
        currentX = startX;
        currentY = startY;
        xBetween = UmlConfig.INSTANCE.getXBetween();
        yBetween = UmlConfig.INSTANCE.getYBetween();
        pictureWidthLimit = UmlConfig.INSTANCE.getLimitWidth();
        maxClassHeight = 0;

    }

    public int[] nextXY(int width,int height){
        if (height > maxClassHeight){
            maxClassHeight = height;
        }
        int[] result = new int[2];
        result[0] = currentX;
        result[1] = currentY;
        currentX += (width + xBetween);
        if (currentX > pictureWidthLimit){
            currentX = startX;
            currentY += (maxClassHeight + yBetween);
        }
        return result;

    }
}
